<?php
/**
 * Created by PhpStorm .
 * User: 杜磊磊
 * Date: 2020/6/24
 * Time: 10:21
 */

namespace app\admin\middleware;

class Auth
{
    public function handle($request, \Closure $next)
    {
//        dump($request->pathinfo);
        //preg_match函数可以根据正则表达式对字符串进行搜索匹配
        //前置中间件
        if (empty(session("adminUser")) && !preg_match("/login/",$request->pathinfo())){
            return redirect(url("login/index"));
        }
        //后置中间件
        $response =  $next($request);
        //if (empty(session("adminUser")) && $request->controller() != "Login"){
        //    return redirect(url("Login/index"));
        //}
        return $response;
    }
}